20230322
[shlib.git] / testing / 3.shlib_v0_1_testing.Testing for shlib v0_1.unit / 4.dbgout_testing.dbgout Testing.unit / 2.debug.sh
blob95a3ea1a49a4630debe48cc3966e567aa743d27d
1 #!/bin/bash
2 ############################################################
3 # source: debug.sh
4 # author: devenkong(18151155@qq.com)
5 # date: 2022-10-10
6 ############################################################
7 # Copyright (C) 2022- Free Software Foundation, Inc.
8 # This configure script is free software; the Free Software
9 # Foundation gives unlimited permission to copy, distribute
10 # and modify it.
11 ############################################################
12 # note:
13 # this is a testing script for debugging based on output
14 # txt strings. it helps programer to find out code file and
15 # lines which output error info.
16 ############################################################
19 # todoļ¼š
20 # @
21 # @
24 . shlibinc
27 ##############################
28 # section: shlib include
29 ##############################
31 include gplib.shlib
32 include dbgout.shlib
35 ##############################
36 # section: public comment info
37 ##############################
42 ##############################
43 # section: variable define
44 ##############################
46 longstr="adhdhjdjfjfjdjdjd
47 djjdjfjjffjjfjdk
48 djdjjedjdhvhvur
49 jfjrriekddnhffk
50 fjkdslsosojf
51 djjrekksijfuvugufhr
52 fjdjdjkjfhfhfhddjj
53 fkkforoeoeidjchshhsejj
54 fjrrbdhhducucjdsjje"
57 ##############################
58 # section: private function
59 ##############################
61 stub_debug ()
64 # here is the example for stub debug
65 # use stub string to seperate application string info,
66 # if some of the code running error, it shows error code where it
67 # is invoked.
70 dbgout "xxxxxxxxxxxx step1 xxxxxxxxxxxx\n"
72 echo 11111
73 dbgout "xxxxxxxxxxxx step2 xxxxxxxxxxxx\n"
75 echo 22222
76 dbgout "xxxxxxxxxxxx step3 xxxxxxxxxxxx\n"
78 echo 33333
79 dbgout "xxxxxxxxxxxx step4 xxxxxxxxxxxx\n"
81 duehehjs
82 dbgout "xxxxxxxxxxxx step5 xxxxxxxxxxxx\n"
84 echo 55555
85 dbgout "xxxxxxxxxxxx step6 xxxxxxxxxxxx\n"
88 func_for_test ()
91 # using stub to locate in src code
92 # it can be used for branch structure code.
94 if [[ 1 == 1 ]]; then
95 dbgout_file_stub
96 dbgout_func_stub
98 echo application string output.
101 # display invoke stack to get the code location.
103 dbgout_trace
108 ##############################
109 # section: public function
110 ##############################
113 # main <eval-str>
115 main ()
117 local testvar=aaa
118 local cnt=0
119 echo "func-paramter:"
121 init_dbglogout 2 shlibopt 20000
123 info "this example shows how to use debug infomation output function in sub-process of while loop."
125 echo xxxxxxxxxxxxxxxxxxxxxxxxx
127 echo testvar=$testvar
130 # use dbgoutvar to display long string by var name.
132 dbgoutvar longstr
135 # display data as hex string.
137 echo dbgout_hex | dbgout_hex
139 while read line; do
140 : $(( cnt++ ))
141 info cnt=$cnt
142 [[ $cnt == 5 ]] && break
144 func_for_test
147 # output string on debug channel
149 dbgout_cmd ls / -l
152 # debug pause as a single step
154 dbgstub_pause
156 info testvar=$testvar
157 echo xxx $line
158 echo "echo string in logfile."
159 dbgout "output debug string here.\n"
160 info "output info string on tty console."
161 done < <(cat sceipts/data.txt) > output.txt
163 echo at last, cnt=$cnt
164 echo output.txt is:
165 cat output.txt
167 echo xxxxxxxxxxxxxxxxxxxxxxxxx
171 main "$@"
173 ##############################
174 # section: file tail
175 ##############################